#ifndef __EMB_TIMER_H
#define __EMB_TIMER_H

#include "emb.h"


#define EMB_TIMER_MODE_CONTINUOUS   1
#define EMB_TIMER_MODE_ONESHOT      0

typedef void (*emb_timer_callback_fn_t)(emb_timer_ctrl_t* Timer);


typedef struct{
    emb_timer_callback_fn_t CallBack;
    size_t Last;
    size_t Period;
    uint32_t Status:1;
    uint32_t Mode:1;
    uint32_t Count : 30;
} emb_timer_ctrl_t;

void emb_timer_prev_init(uint8_t* Buf,size_t BufSize);

void emb_timer_init(emb_timer_ctrl_t *Timer, size_t Period, uint8_t Mode, uint32_t Count, emb_timer_callback_fn_t CallBack);

void emb_timer_start(emb_timer_ctrl_t *Timer);

void emb_timer_stop(emb_timer_ctrl_t *Timer);

void emb_timer_handler();

size_t emb_timer_next_timeout();


#endif
